package com.example.desksginktapp.views

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.baselibrary.bases.Constants
import com.example.baselibrary.utlis.AppCache
import com.example.baselibrary.utlis.setOnSingleClickListener
import com.example.desksginktapp.R
import com.example.desksginktapp.databinding.ActivitySettingBinding
import com.example.desksginktapp.viewmodels.SettingViewModel
import com.example.httplibrary.https.RetrofitClient
import com.zyf.baselibrary.base.BaseViewBindingActivity

class SettingActivity : BaseViewBindingActivity<ActivitySettingBinding, SettingViewModel>() {
    override fun provideViewModel(): SettingViewModel {
        return SettingViewModel()
    }

    override fun initViews() {
        super.initViews()
        // 初始化缓存中的开关状态
        binding.btSettingMustId.isChecked = mAcache?.getAsBoolean(Constants.IDCARD_SIGN, false) ?: false
        binding.btSettingMustQr.isChecked = mAcache?.getAsBoolean(Constants.QRCODE_SIGN, false) ?: false
        binding.btSettingMustInput.isChecked = mAcache?.getAsBoolean(Constants.INPUT_SIGN, false) ?: false
        var url = AppCache.get()?.getAsString(Constants.URL) ?: "";
        if (url.isNotEmpty()){
            binding.etBaseUrl.setText(url)
        }else{
            binding.etBaseUrl.setText("https://xrpt.xr2004.com/ajhd/")
        }

        binding.btSettingMustId.setOnSingleClickListener {
            mAcache?.put(Constants.IDCARD_SIGN, binding.btSettingMustId.isChecked)
        }
        binding.btSettingMustQr.setOnSingleClickListener {
            mAcache?.put(Constants.QRCODE_SIGN, binding.btSettingMustQr.isChecked)
        }
        binding.btSettingMustInput.setOnSingleClickListener {
            mAcache?.put(Constants.INPUT_SIGN, binding.btSettingMustInput.isChecked)
        }

        binding.llMainSetting.setOnSingleClickListener {
            mAcache?.put(Constants.URL, binding.etBaseUrl.text.toString())
            RetrofitClient.setBaseUrl(binding.etBaseUrl.text.toString())
            finish()
        }

    }

    override fun initData() {
        super.initData()
    }

}